// pages/end1/end1.js
var app = getApp()
const db = wx.cloud.database()

let title = ""
// let openid = ""
// let userInfo = ""


app.globalData.title = title
// app.globalData.userInfo= userInfo
// app.globalData.openid = openid
// openid  = app.globalData.openid


var util = require('../../utils/util.js');


Page({

  /**
   * 页面的初始数据
   */
  data: {
    "hasload":"",
    "toggleDelay": false,
    "loaddate": "",
    "date": "",
    "time": "",
    "openid": "",
    bottom: [{
      id: 0,
      text: "首页",
      selectedIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/6.0.0.png?sign=8efcdca8770c182531fd1d0a5b98bee7&t=1621066787",
      selectIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/6.0.1.png?sign=4b58233a9a18aed2b79064b59005387e&t=1621066799",
    }, {
      id: 1,
      text: "活动",
      selectIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/7.0.0.png?sign=012969fbfc15e20d6ae5c4a6c9d67f5a&t=1621066822",
      selectedIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/7.0.1.png?sign=837e43574ead133a890d0afe82a79415&t=1621066837",
    }, {
      id: 2,
      text: "收藏",
      selectIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/8.0.0.png?sign=8a80489dff605f44d9507571a1512f7d&t=1621066859",
      selectedIcon: "",
    }, {
      id: 3,
      text: "我的",
      selectedIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/9.0.1.png?sign=ded7f69596df7b109d7bc7516da3ac2c&t=1621066877",
      selectIcon: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/icon/9.0.0.png?sign=99cccb8c719d8d43d1aa4f040d5b3a1c&t=1621069715",
    }],
    showView1: true,
    showView2: true,
    "userInfo": [],
    // hasUserInfo: false,
    canIUseGetUserProfile: false,
  },

  // 动效代码
  // toggle: function(e) {
  //   console.log("shalaid ",e);
  //   var anmiaton = e.currentTarget.dataset.class;
  //   var that = this;
  //   that.setData({
  //     animation: anmiaton
  //   })
  //   setTimeout(function() {
  //     that.setData({
  //       animation: ''
  //     })
  //   }, 1000)
  // },

  bottomJump: function (e) {
    console.log(e.currentTarget.dataset.bottomitemdata)
    if ("首页" === e.currentTarget.dataset.bottomitemdata) {
      wx.navigateTo({
        url: '../../pages/end/end'
      })

    } else if ("活动" === e.currentTarget.dataset.bottomitemdata) {
      wx.navigateTo({
        url: '../../pages/end1/end1'
      })
    } else if ("收藏" === e.currentTarget.dataset.bottomitemdata) {
      wx.navigateTo({
        url: '../../pages/end2/end2'
      })
    } else if ("我的" === e.currentTarget.dataset.bottomitemdata) {
      wx.navigateTo({
        url: '../../pages/end3/end3'
      })
    }
  },

  onChangeShowState1: function () {
    var that = this;
    that.setData({
      showView1: (!that.data.showView1)
    })
  },


  getopenid() {
    var that = this
    wx.cloud.callFunction({

      name: "getopenid",
      success(res) {
        console.log("获取openid成功", res.result.openid)
        console.log(res)
        that.setData({
          openid: res.result.openid

        })
        console.log()
        wx.setStorage({
          key:"openid",
          data:that.data.openid
        })
        getApp().globalData.openid = that.data.openid


      },
      fail(res) {
        console.log("获取openid成功", res)
      }
    })
  },



  getUserProfile(e) {
    var that = this
    console.log(e)
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认
    // 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    if (getApp().globalData.openid == null) {
      wx.getUserProfile({
        desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
        success: (res) => {
          console.log("返回",res)
          // wx.setStorage({
          //   key:"userInfo",
          //   data:"res.userInfo"
          // })
          that.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
          wx.setStorage({
            key:"userInfo",
            data:res.userInfo
          })

       
          getApp().globalData.userInfo = res.userInfo
          this.getopenid()

        }
      })
    } else {
      console.log("有了", e)

      this.setData({

        hasUserInfo: true
      })
    }
  },

  jumpshangchuan: function (e) {
    console.log(e)
    
      wx.navigateTo({
        url: '../../pages/end4/end4'
      })

    
  },

 qushoucang: function (e) {
    console.log(e)
    
      wx.navigateTo({
        url: '../../pages/end2/end2'
      })

    
  },
  
  // getUserInfo(e) {
  // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
  //   console.log(res)
  //   this.setData({
  //     userInfo: e.detail.userInfo,
  //     hasUserInfo: true
  //   })
  // },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var TIME = util.formatTime(new Date());
    console.log(TIME)

    this.setData({
      "time_start": TIME,
      "loaddate": new Date().getTime(),
      // "userInfo": getApp().globalData.userInfo,
      // "openid": getApp().globalData.openid,
      // hasUserInfo: true

    });
    console.log(this.data.loaddate)



    var DATE = util.formatDate(new Date());


    this.setData({

      date_start: DATE,
      date_cut: DATE

    })
    showView1: (options.showView1 == "true" ? true : false)
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  onShow: function (options) {
    var that = this;
    console.log("res1", options)

    that.setData({
      title: getApp().globalData.title,
      openid: getApp().globalData.openid,
      userInfo: getApp().globalData.userInfo

    })
    if (getApp().globalData.openid == null) {

    } else {
      

      this.setData({
       
      })
  }
  that.getUserProfile()

   
  },


  // 动效代码
  // toggle(e) {
  //   console.log(e);
  //   var anmiaton = wx.createAnimation({
  //     name: fade,
  //     duration: 800,
  //    timingfunction: "linear",
  //   })
  //   var that = this;
  //   that.setData({
  //     animation: anmiaton
  //   })
  //   setTimeout(function() {
  //     that.setData({
  //       animation: ''
  //     })
  //   }, 1000)
  // },
  // toggleDelay() {
  //   var that = this;
  //   that.setData({
  //     toggleDelay: true
  //   })
  //   setTimeout(function() {
  //     that.setData({
  //       toggleDelay: false
  //     })
  //   }, 1000)
  // }




})